﻿using System.Web.Mvc;
using Freedom.Framework.Logging;

namespace Freedom.Framework.Mvc.Filter
{
    public class LogActionFilter: ActionFilterAttribute
    {
        private ILogger _logger = new NullLogger();

        public ILogger Logger
        {
            get { return _logger; }
            set { _logger = value; }
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            _logger.Debug(string.Format("Controller-{0} Action-{1} :end",
                    filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                    filterContext.ActionDescriptor.ActionName
                ));
        }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            _logger.Debug(string.Format("Controller-{0} Action-{1} :begin",
                    filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                    filterContext.ActionDescriptor.ActionName
                ));
        }
    }
}
